// 所有模块都通过 define 来定义
define(function (require, exports, module) {
	require("common");
	$.get("/app/pay/checkBinding.html", function(data) {
		if(data.resCode==1){
		}else{
			var url = "/mobile/usercenter/useridentify/bank.html";
			layer.alert(data.resMsg+",3秒后自动跳转", function(index){
				window.location.href = url;
			});			
			setTimeout(function(){
                window.location.href = url;
            },3000);
		}
	});
	//快捷支付，缺少获取验证码action
	$("#getPhoneCodeEdit").on("click",function(){
		var _that = this;
		if($("#rechargeNumber").val()==""){
			showError("rechargeNumber","请输入充值金额");
			return;
		}else if($("#rechargeNumber").val()<100){
			showError("rechargeNumber","最小充值金额为100元");
			return;
		}
		resultFlag = false;
		get_code_time(_that);
		$.post("/app/pay/quickPay.html?money="+$("#rechargeNumber").val(), function(data) {
			if(data.resCode==1){
				layer.alert("发送成功");
			}else{
				resultFlag = true;
				layer.alert(data.resMsg);
			}
		});
	});

	//只适用在有validate的Form的提示用
	function showError(elem,errorTip){
		if($("#"+elem+"-error").length==0){
			var label = '<label id="'+elem+'-error" class="error" for="'+elem+'">'+errorTip+'</label>';
			$("#"+elem).parent().append(label);
		}else{
			$("#"+elem+"-error").html(errorTip);
		}
	}

	var wait = 60;
	var resultFlag = false;
	get_code_time = function (elem) {
		if (wait == 0 || resultFlag==true) {
			$(elem).text("重新发送");
			$(elem).next().hide();
			$(elem).show();
			wait = 60;
		} else {
			$(elem).next().text("("+wait+")秒后重新获取");
			$(elem).hide();
			$(elem).next().show();
			wait--;
			setTimeout(function() {
				get_code_time(elem);
			}, 1000);
		}
	};

	$("#recharge-form").validate({
		rules : {
			'money' : {
				required : true,
				min:100
			}
		},
		messages : {
			'money' : {
				required:"请输入充值金额",
				min:"最小充值金额为100元"
			}
		}
	});
});